<template>
  <div>
    <el-container>
      <el-header class="homeHeader">
        <div class="title">我要当老板队-人力资源管理系统 💼</div>
        <div>
          <!-- 迭代1注释 -->
          <!-- <el-button
            icon="el-icon-bell"
            type="text"
            style="margin-right: 8px; color: #000000"
            size="normal"
            @click="goChat"
          ></el-button> -->
          <!-- 迭代1注释 -->
          <el-dropdown class="userInfo" @command="commandHandler">
            <span class="el-dropdown-link">
              {{ user.name }}<i><img :src="user.userface" alt="" /></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <!-- 迭代1注释 -->
              <!-- <el-dropdown-item command="userinfo">个人中心</el-dropdown-item>
              <el-dropdown-item command="setting">设置</el-dropdown-item>
              <el-dropdown-item command="logout" divided
                >登出账号</el-dropdown-item
              > -->
              <!-- 迭代1注释 -->

              <!-- 迭代1新增 -->
              <el-dropdown-item command="logout">登出账号</el-dropdown-item>
              <!-- 迭代1新增 -->


            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px"
      color="#545c64"
        >
          <!-- 迭代1新增 -->
          <el-menu 
                  router 
                  :unique-opened='false'
                  background-color="#545c64"
                  text-color="#fff"
                  active-text-color="#409EFF">
          <!-- 迭代1新增 -->
          <!-- 迭代1注释
          <el-menu router unique-opened> -->
          <!-- 迭代1注释 -->
            <el-submenu
              :index="index + ''"
              v-for="(item, index) in routes"
              v-if="!item.hidden"
              :key="index"
            >
              <template slot="title">
                <i
                  style=" margin-right: 15px"
                  :class="item.iconCls"
                ></i>
                <span>{{ item.name }}</span>
              </template>
              <el-menu-item
                :index="child.path"
                v-for="(child, indexj) in item.children"
                :key="indexj"
              >
                {{ child.name }}
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <el-breadcrumb
            separator-class="el-icon-arrow-right"
            v-if="this.$router.currentRoute.path != '/home'"
          >
            <el-breadcrumb-item :to="{ path: '/home' }"
              >首页</el-breadcrumb-item
            >
            <el-breadcrumb-item>{{
              this.$router.currentRoute.name
            }}</el-breadcrumb-item>
          </el-breadcrumb>
          <div
            class="homeWelcome"
            v-if="this.$router.currentRoute.path == '/home'"
          >
            人力资源管理系统首页🏡🌥️
          </div>
          <router-view class="homeRouterView" />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      // user: JSON.parse(window.sessionStorage.getItem("user"))
    };
  },
  computed: {
    routes() {
      // console.log(this.$store.state.routes);
      // 迭代1注释
      // return this.$store.state.routes;
      // 迭代1注释
      
      // 迭代2注释
      // // 迭代1新增
      // if(this.$store.state.routes.length == 0){
      //   return this.$store.state.routes
      // }
      // var a = this.$store.state.routes[4]
      // a.children = [a.children[0]]
      // return [a];
      // // 迭代1新增
      // 迭代2注释

      //迭代3注释
      // //迭代2新增
      // if(this.$store.state.routes.length == 0){
      //   return this.$store.state.routes
      // }
      // var xitongguanli = this.$store.state.routes[4]
      // var renshiguanli = this.$store.state.routes[0]
      
      

      // xitongguanli.children = [xitongguanli.children[0]]
      // return [xitongguanli,renshiguanli];
      // //迭代2新增
      //迭代3注释
      //迭代3新增
      if(this.$store.state.routes.length == 0){
        return this.$store.state.routes
      }
      var xitongguanli = this.$store.state.routes[4]
      var renshiguanli = this.$store.state.routes[0]
      var xinziguanli = this.$store.state.routes[2]
      

      xitongguanli.children = [xitongguanli.children[0]]
      xinziguanli.children = [xinziguanli.children[0],xinziguanli.children[1]]
      return [xitongguanli,renshiguanli,xinziguanli];
      //迭代3新增
    },

    user() {
      return this.$store.state.currentHr;
    },
  },
  methods: {
    goChat() {
      this.$router.push("/chat");
    },
    commandHandler(cmd) {
      if (cmd == "logout") {
        this.$confirm("此操作将注销登录, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.getRequest("/logout");
            window.sessionStorage.removeItem("user");
            this.$store.commit("initRoutes", []);
            this.$router.replace("/");
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消操作",
            });
          });
      } else if (cmd == "userinfo") {
        this.$router.push("/hrinfo");
      }
    },
  },
};
</script>

<style>
.homeRouterView {
  margin-top: 10px;
}

.homeWelcome {
  text-align: center;
  font-size: 30px;
  /* font-family: ; */
  color: #2e2f30;
  padding-top: 50px;
}

.homeHeader {
  background-color: #303539;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 15px;
  box-sizing: border-box;
}

.homeHeader .title {
  font-size: 20px;
  /* font-family: 华文行楷; */
  color: #ffffff;
}

.homeHeader .userInfo {
  
  color:#ffffff;
  cursor: pointer;
}
  .el-aside {
    background-color: #545c64;
    /* color: #333; */
    /* text-align: center; */
    /* line-height: 200px; */
    /* height:100%; */
    
  height: 100vh;
  }

  .el-main{

  }
.el-dropdown-link img {
  width: 48px;
  height: 48px;
  border-radius: 24px;
  margin-left: 8px;
}

.el-dropdown-link {
  display: flex;
  align-items: center;
}
</style>